﻿
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 * 
 * C O P Y R I G H T    N O T I C E
 * 
 * Copyright (c) 2000-2010 Acidaes Solutions Pvt. Ltd. All Rights Reserved.
 * 
 * This code is a part of the source code used by Acidaes Solution Private Limited for its product "BusinessNext".
 * You may not, directly or indirectly, use, disclose, distribute, print or copy this code or any part of it.
 * 
 * This code contains confidential information and/or may contain information protected by intellectual property 
 * rights or other rights. This code shall/may not be construed to constitute any commitment from 
 * Acidaes Solutions Private Limited or its subsidiaries or affiliates except when expressly agreed to in a 
 * separate written agreement.
 * 
 * AUTHORS:                           DATE:
 * 
 * REVISION: $Revision: 5420 $
 * LAST MODIFIED BY: &Author$ on $Date: 2007-06-16 12:01:05 +0530 (Sat, 16 Jun 2007) $  
 * 
 * R E V I S I O N  H I S T O R Y:
 * 
 * DATE      CHANGED BY               COMMENT     
 * 
 *  
 * C O D E  R E V I E W  H I S T O R Y: 
 * 
 * DATE      REVIEWED BY              COMMENT     
 *  
 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NUnit.Framework;
using Acidaes.Caching;
using System.Configuration.Provider;
using System.Threading;

namespace UnitTest
{
    [TestFixture]
    public class UnitTests
    {
        public const string TestObjectKey = "Acidaes Solution Pvt. Ltd.";

        [SetUp]
        public void Init()
        {
        }

        [Test]
        public void LoadProviders()
        {
            try
            {
                CacheProvider provider = new CacheClient().Provider;
                if (provider == null)
                    Assert.Fail("Could Not Load Default Provider");
            }
            catch (Exception ex) 
            {
                Assert.Fail(ex.Message);
            }
            
        }
        [Serializable]
        public class TestData
        {
            public TestData() { }

            public string FieldA;
            public string FieldB;
            public int FieldC;
            public bool FieldD;
        }


        [Test]
        public void StoreObjectTest()
        {
            TestData td = new TestData();
            td.FieldA = "Hello";
            td.FieldB = "World";
            td.FieldC = 19810619;
            td.FieldD = true;
            CacheClient cu = new CacheClient();
            cu.Put(TestObjectKey, td);
        }


        [Test]
        public void GetObjectTest()
        {
            TestData td =(TestData) (new CacheClient().Get(TestObjectKey));

            Assert.IsNotNull(td, "Get returned null.");
            Assert.AreEqual(td.FieldA, "Hello", "Object was corrupted.");
            Assert.AreEqual(td.FieldB, "World", "Object was corrupted.");
            Assert.AreEqual(td.FieldC, 19810619, "Object was corrupted.");
            Assert.AreEqual(td.FieldD, true, "Object was corrupted.");
        }
        [Test]
        public void DeleteObjectTest()
        {
            CacheClient cu = new CacheClient();
            cu.Remove(TestObjectKey);

            Assert.IsNull(cu.Get(TestObjectKey), "Remove failed.");
        }


        [Test]
        public void ExpirationTest()
        {
            CacheClient cc = new CacheClient();

            cc.Add(null, "ExpirationTest:TimeSpan", "ExpirationTest:TimeSpan", new TimeSpan(0, 0, 5));

            Assert.AreEqual("ExpirationTest:TimeSpan", cc.Get("ExpirationTest:TimeSpan"), "Expires:Timespan store failed");

            Thread.Sleep(8000);
            Assert.IsNull(cc.Get("ExpirationTest:TimeSpan"), "ExpirationTest:TimeSpan item did not expire");

        }

    }
}
